home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_08 / phillip2 / mainhist.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-19  |  3.1 KB  |  122 lines

  1.  
  2.     /***********************************************
  3.     *
  4.     *  file d:\cips\mainhist.c
  5.     *
  6.     *  Functions: This file contains
  7.     *     main
  8.     *
  9.     *  Purpose:
  10.     *     This file contains the main calling
  11.     *     routine which will perform histogram
  12.     *     equalization on an input image to
  13.     *     produce an output image.
  14.     *
  15.     *  External Calls:
  16.     *     gpcips.c - my_clear_text_screen
  17.     *     tiff.c - read_tiff_header
  18.     *     rtiff.c - read_tiff_image
  19.     *     wtiff.c - write_array_into_tiff_image
  20.     *     hist.c - calculate_histogram
  21.     *              zero_histogram
  22.     *              perform_histogram_equalization
  23.     *
  24.     *  Modifications:
  25.     *     17 March 1992 - created
  26.     *
  27.     *************************************************/
  28.  
  29. #include "cips.h"
  30.  
  31.  
  32. short the_image[ROWS][COLS];
  33. short out_image[ROWS][COLS];
  34.  
  35. main(argc, argv)
  36.    int argc;
  37.    char *argv[];
  38. {
  39.  
  40.    char  name[80], name2[80];
  41.    float new_grays, area;
  42.    int   count, i, ie, il,
  43.          j, le, length, ll, width;
  44.  
  45.    unsigned long histogram[256], new_hist[256];
  46.  
  47.  
  48.    struct   tiff_header_struct image_header;
  49.  
  50.    my_clear_text_screen();
  51.  
  52.    if(argc < 3){
  53.     printf("\n\nNot enough parameters:");
  54.     printf("\n");
  55.     printf("\n   usage: mainhist in-file out-file  ");
  56.     exit(0);
  57.    }
  58.  
  59.    strcpy(name, argv[1]);
  60.    strcpy(name2, argv[2]);
  61.  
  62.    create_file_if_needed(name, name2, the_image);
  63.  
  64.    il = 1;
  65.    ie = 1;
  66.    ll = ROWS+1;
  67.    le = COLS+1;
  68.  
  69.    read_tiff_header(name, &image_header);
  70.  
  71.    length = (ROWS-10 + image_header.image_length)/ROWS;
  72.    width  = (COLS-10 +image_header.image_width)/COLS;
  73.    count  = 1;
  74.    printf("\nlength=%d  width=%d", length, width);
  75.  
  76.    zero_histogram(histogram);
  77.    zero_histogram(new_hist);
  78.  
  79.  
  80.    for(i=0; i<length; i++){
  81.       for(j=0; j<width; j++){
  82.         printf("\nCalculating Histogram %d of %d",
  83.                count, length*width);
  84.         count++;
  85.  
  86.          read_tiff_image(name, the_image, 
  87.                          il+i*ROWS, ie+j*COLS, 
  88.                          ll+i*ROWS, le+j*COLS);
  89.          calculate_histogram(the_image, histogram);
  90.  
  91.  
  92.       } /* ends loop over j */
  93.    }  /* ends loop over i */
  94.  
  95.  
  96.    area      = ((long)(length))*((long)(width));
  97.    area      = area*10000.0;
  98.    new_grays = 250;
  99.  
  100.    count = 1;
  101.  
  102.    for(i=0; i<length; i++){
  103.       for(j=0; j<width; j++){
  104.         printf("\nDoing equalization %d of %d",
  105.                count, length*width);
  106.         count++;
  107.  
  108.          read_tiff_image(name, the_image,
  109.                         il+i*ROWS, ie+j*COLS,
  110.                         ll+i*ROWS, le+j*COLS);
  111.          perform_histogram_equalization(the_image,
  112.                                         histogram,
  113.                                         new_grays,
  114.                                         area);
  115.          write_array_into_tiff_image(name2, the_image,
  116.                                 il+i*ROWS, ie+j*COLS,
  117.                                 ll+i*ROWS, le+j*COLS);
  118.       } /* ends loop over j */
  119.    }  /* ends loop over i */
  120.  
  121. }  /* ends main  */
  122.